<?php
namespace AdminApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class SendnewsletterApiController extends AbstractRestfulController
{
    public function getList()
    {
		header('Access-Control-Allow-Origin: *');
		
    }
    public function get($mOrderId)
    {	
		header('Access-Control-Allow-Origin: *');
		
    }
    public function create($data)
    {
		header('Access-Control-Allow-Origin: *');
		global $newslettermailsubject;				
		global $newslettermailMessage;
		$subscribeTable=$this->getServiceLocator()->get('Models\Model\SubscribeFactory');
		$Sentnotificationto_allsubscribers=$subscribeTable->allsubscribers();
		if($Sentnotificationto_allsubscribers->count()>0)
		{ 			
			foreach($Sentnotificationto_allsubscribers as $mailcontent)
			{				
				$to=$mailcontent->subscrib_email;
				$Email= $mailcontent->subscrib_email;
				$mesage=$data['subject'];
				$subject=$data['message'];
				$body=$newslettermailMessage;
				$body = str_replace("<FULLNAME>",$Email, $body);
				$body = str_replace("<SUBJECT>",$subject, $body);
				$body = str_replace("<MESSAGE>",$mesage, $body);
				$sentmailall=sendMail($to,$newslettermailsubject,$body);
				if($sentmailall){
					return new JsonModel(array(
						'status'	=> 'Mail Sent Successfully',
						'value'		=> 1,
					));
				}else{
					return new JsonModel(array(
						'status'	=> 'Mail Not Sent Successfully',
						'value'		=> 0,
					));
				}
			}
		}else{
				return new JsonModel(array(
					'status'	=> 'No Data',
					'value'		=> 0,
				));
			}
	}
    public function update($orderId,$order)
    {
		header('Access-Control-Allow-Origin: *');
    }
    public function delete($id)
    {
       
    }
}